/**
 * http://usejsdoc.org/
 */
var http = require('http'),
	fs = require('fs'),
	url = require('url'),
	staticModule = require('./static_module');


function goIndex(res){
	var realPath = __dirname + '/'+ url.parse('index.html').pathname;
	var indexPage = fs.readFileSync(realPath);
	res.writeHead( 200 , {"Content-Type":"text/html"});
	res.end(indexPage);
}

/**创建http服务器*/
http.createServer(function(req,res){
	/**web客户端请求*/
	var pathname = url.parse(req.url).pathname;//获取url请求路径
	var realPath = __dirname +'/static'+ pathname;
	if('/favicon.ico' === pathname){
		return;
	}else if(pathname === '/index' || pathname === '/'){
		goIndex(res);
	}else{
		staticModule.getStaticFile(pathname,res,req);
	}
}).listen(8080,'127.0.0.1');

console.log('Server running at http://127.0.0.1:8080');